// FTLibOpenCL.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include "FTLibOpenCL.h"
#include "include_clfft.h"

bool clFFT_CheckAvailability()
{
	cl_uint num_platforms = 0;
	cl_int r = clGetPlatformIDs(
		0				/* num_entries */,
		NULL			/* platforms */,
		&num_platforms  /* num_platforms */);

	if (r != CL_SUCCESS || num_platforms == 0)
	{
		return false;
	}

	return true;
}

static bool copyToDestString(const char* szSrc, char* szDest, size_t* pLength)
{
	if (pLength == nullptr)
	{
		return false;
	}

	size_t l = strlen(szSrc);

	if (*pLength <= l)
	{
		*pLength = l;
		return false;
	}

	if (szDest != nullptr)
	{
		strcpy_s(szDest, *pLength, szSrc);
	}

	*pLength = l;
	return true;
}

bool clFft_GetVersionString(char* sz, size_t* pLength)
{
	if (!clFFT_CheckAvailability())
	{
		return copyToDestString("ERROR", sz, pLength);
	}

	cl_uint major, minor, patch;
	clfftGetVersion(&major, &minor, &patch);

	std::stringstream ss;
	ss << "major=" << major << ", minor=" << minor << ", patch=" << patch;
	return copyToDestString(ss.str().c_str(), sz, pLength);
}

//// This is an example of an exported variable
//FTLIBOPENCL_API int nFTLibOpenCL=0;
//
//// This is an example of an exported function.
//FTLIBOPENCL_API int fnFTLibOpenCL(void)
//{
//	return 42;
//}
//
//// This is the constructor of a class that has been exported.
//// see FTLibOpenCL.h for the class definition
//CFTLibOpenCL::CFTLibOpenCL()
//{
//	return;
//}
